package mark.tom.friend.provider.impl;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import com.alibaba.android.arouter.facade.annotation.Route;
import mark.tom.friend.base.util.SystemUtil;
import mark.tom.friend.consts.ProviderRouterConsts;
import mark.tom.friend.provider.ISystemProvider;
import timber.log.Timber;

import java.util.List;

@Route(path = ProviderRouterConsts.ROUTER_PROVIDER_SYSTEM)
public class SystemProviderImpl implements ISystemProvider {

    private PackageManager packageManager;

    @Override
    public PackageManager getPackageManager() {
        return packageManager;
    }

    @Override
    public List<PackageInfo> getPackageInfoList() {
        List<PackageInfo> result = null;
        try {
            result = SystemUtil.getInstalledPackages(packageManager);
        } catch (Exception ex) {
            Timber.e(ex);
        }
        return result;
    }

    @Override
    public Drawable getAppIconByPackageName(String packageName) {
        return SystemUtil.getAppIcon(packageManager, packageName);
    }

    @Override
    public String[] getAppSignatureByPackageName(String packageName) {
        return SystemUtil.getAppSignature(packageManager, packageName);
    }

    @Override
    public void init(Context context) {
        packageManager = context.getPackageManager();
    }
}
